//
//  LJJGoodsDetailTitleLabelView.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/18.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJGoodsDetailTitleLabelView.h"

@interface LJJGoodsDetailTitleLabelView ()

@property (strong, nonatomic) UILabel *titleLabel;    /** 标题 **/
@property (strong, nonatomic) UILabel *priceLabel;    /** 价格 **/
@property (strong, nonatomic) UIView *priceLineView;    /** 价格下面的分割线 **/
@property (strong, nonatomic) UILabel *contentLabel;    /** 描述信息 **/
@property (strong, nonatomic) UIButton *nextViewButton;    /** 跳转商户信息 **/
@property (strong, nonatomic) UILabel *shopName;    /** 商店名 **/
@property (strong, nonatomic) UIImageView *shopImageView;    /** 商店图片 **/
@property (strong, nonatomic) UIImageView *countryImageView;    /** 国家图片 **/
@property (strong, nonatomic) UILabel *countryLabel;    /** 国家名 **/
@property (strong, nonatomic) UIImageView *nextImageView;    /** 箭头 **/
@property (strong, nonatomic) UIView *backView;    /** 去商店信息上面的view **/
@property (strong, nonatomic) UILabel *tostTitleLabel;    /** 图文详情 **/
@property (strong, nonatomic) UIView *tostLineView;    /** 提示文字线 **/

@end

@implementation LJJGoodsDetailTitleLabelView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.priceLineView];
        [self addSubview:self.contentLabel];
        [self addSubview:self.backView];
        [self addSubview:self.nextViewButton];
        [self addSubview:self.shopName];
        [self addSubview:self.shopImageView];
        [self addSubview:self.countryImageView];
        [self addSubview:self.countryLabel];
        [self addSubview:self.nextImageView];
        [self addSubview:self.tostTitleLabel];
        [self addSubview:self.tostLineView];
        [self addLayout];
    }
    return self;
}
- (void)setModel:(LJJDetailTitleViewModel *)model
{
    _model = model;
    CGFloat height = 260.0;
    _titleLabel.text = model.Abbreviation;
    CGFloat titleLabelHeight = [NSString configLabelHeight:_titleLabel.text width:WIDTH - 60 font:[UIFont boldSystemFontOfSize:16.0]];
    [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(titleLabelHeight);
    }];
    _priceLabel.text = [NSString stringWithFormat:@"%@ %@ %@", model.Price, model.OriginalPrice, model.Discount];
    _contentLabel.text = model.GoodsIntro;
    CGFloat contentHeight = [NSString configLabelHeight:_contentLabel.text width:WIDTH - 30 font:[UIFont systemFontOfSize:14.0]];
    [_contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(contentHeight);
    }];
    [_shopImageView sd_setImageWithURL:[NSURL URLWithString:model.ShopImage]];
    _shopName.text = model.BrandCNName;
    _countryLabel.text = model.CountryName;
    if (_heightBlock) {
        _heightBlock(height + titleLabelHeight + contentHeight);
    }
}
- (void)setCountryImage:(NSString *)countryImage
{
    _countryImage = countryImage;
    [_countryImageView sd_setImageWithURL:[NSURL URLWithString:_countryImage]];
}
#pragma mark -
#pragma mark - method
- (void)addLayout
{
    __weak typeof(self) weakSelf = self;
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.height.equalTo(@40);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf);
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(25);
        make.height.equalTo(@20);
    }];
    [_priceLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.priceLabel.mas_bottom).offset(25);
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.height.equalTo(@1);
    }];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.top.equalTo(weakSelf.priceLineView.mas_bottom).offset(20);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.height.equalTo(@20);
    }];
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(weakSelf);
        make.height.equalTo(@100);
        make.top.equalTo(weakSelf.contentLabel.mas_bottom).offset(18);
    }];
    [_nextViewButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.backView).with.insets(UIEdgeInsetsMake(10, 0, 10, 0));
    }];
    [_shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.nextViewButton.mas_centerY);
        make.left.equalTo(weakSelf.nextViewButton.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    [_shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.shopImageView.mas_top).offset(5);
        make.left.equalTo(weakSelf.shopImageView.mas_right).offset(15);
        make.height.equalTo(@12);
        make.right.equalTo(weakSelf.mas_right).offset(-120);
    }];
    [_countryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(18, 13));
        make.left.equalTo(weakSelf.shopImageView.mas_right).offset(15);
        make.bottom.equalTo(weakSelf.shopImageView.mas_bottom).offset(-5);
    }];
    [_countryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.countryImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(70, 15));
        make.left.equalTo(weakSelf.countryImageView.mas_right).offset(5);
    }];
    [_nextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(10, 15));
        make.centerY.equalTo(weakSelf.shopImageView.mas_centerY);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
    }];
    [_tostTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(70, 50));
        make.top.equalTo(weakSelf.backView.mas_bottom);
    }];
    [_tostLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@1);
        make.top.equalTo(weakSelf.tostTitleLabel.mas_bottom);
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
    }];
}
#pragma mark -
#pragma mark - lazy method
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15.0];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}
- (UILabel *)priceLabel
{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLabel;
}
- (UIView *)priceLineView
{
    if (!_priceLineView) {
        _priceLineView = [[UIView alloc] init];
        _priceLineView.backgroundColor = RGB(242, 242, 242, 1);
    }
    return _priceLineView;
}
- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = RGB(83, 83, 83, 1);
        _contentLabel.font = [UIFont systemFontOfSize:13.0];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}
- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = MAINCOLOR;
    }
    return _backView;
}
- (UIButton *)nextViewButton
{
    if (!_nextViewButton) {
        _nextViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _nextViewButton.backgroundColor = [UIColor whiteColor];
    }
    return _nextViewButton;
}
- (UILabel *)shopName
{
    if (!_shopName) {
        _shopName = [[UILabel alloc] init];
        _shopName.font = [UIFont systemFontOfSize:12.0];
    }
    return _shopName;
}
- (UIImageView *)shopImageView
{
    if (!_shopImageView) {
        _shopImageView = [[UIImageView alloc] init];
    }
    return _shopImageView;
}
- (UILabel *)countryLabel
{
    if (!_countryLabel) {
        _countryLabel = [[UILabel alloc] init];
        _countryLabel.font = [UIFont systemFontOfSize:12.0];
    }
    return _countryLabel;
}
- (UIImageView *)countryImageView
{
    if (!_countryImageView) {
        _countryImageView = [[UIImageView alloc] init];
    }
    return _countryImageView;
}
- (UIImageView *)nextImageView
{
    if (!_nextImageView) {
        _nextImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"下一步"]];
    }
    return _nextImageView;
}
- (UILabel *)tostTitleLabel
{
    if (!_tostTitleLabel) {
        _tostTitleLabel = [[UILabel alloc] init];
        _tostTitleLabel.text = @"图文详情";
        _tostTitleLabel.font = [UIFont systemFontOfSize:14.0];
    }
    return _tostTitleLabel;
}
- (UIView *)tostLineView
{
    if (!_tostLineView) {
        _tostLineView = [[UIView alloc] init];
        _tostLineView.backgroundColor = RGB(242, 242, 242, 1);
    }
    return _tostLineView;
}
@end
